//js获取项目根路径，如： http://localhost:8083/uimcardprj
function getRootPath(){
    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath=window.document.location.href;
    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8083
    var localhostPaht=curWwwPath.substring(0,pos);
    //获取带"/"的项目名，如：/uimcardprj
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
    
    var basePath = (localhostPaht+projectName);
    if(basePath.indexOf("ieventvm")==-1){
 	   basePath=localhostPaht+"/shops";
    }else{
    	basePath+="/shops"
    }
    return basePath;
}
//上移
function arrowUp(obj)
{
 	var onthis = $(obj).parent();
 	var getup = $(obj).parent().prev();
 	if(getup.get(0) != undefined){
	 	var onthis_sort = onthis.find("#sort").val();
	 	var getup_sort = getup.find("#sort").val();
	 	//排序号重新赋值
	 	onthis.find("#sort").val(getup_sort);
	 	getup.find("#sort").val(onthis_sort);
 	}
 	$(getup).before(onthis);
}
//下移
function arrowDown(obj)
{
 	var onthis = $(obj).parent();
 	var getdown = $(obj).parent().next();
 	if(getdown.get(0) != undefined){
	 	var onthis_sort = onthis.find("#sort").val();
	 	var getdown_sort = getdown.find("#sort").val();
	 	//排序号重新赋值
	 	onthis.find("#sort").val(getdown_sort);
	 	getdown.find("#sort").val(onthis_sort);
 	}
 	$(getdown).after(onthis);
}
//上移
function arrowUpTr(obj)
{
 	var onthis = $(obj).parent().parent();
 	var getup = $(obj).parent().parent().prev();
 	if(getup.get(0) != undefined){
	 	var onthis_sort = onthis.find("#sort").val();
	 	var getup_sort = getup.find("#sort").val();
	 	//排序号重新赋值
	 	onthis.find("#sort").val(getup_sort);
	 	getup.find("#sort").val(onthis_sort);
 	}
 	$(getup).before(onthis);
}
//下移
function arrowDownTr(obj)
{
 	var onthis = $(obj).parent().parent();
 	var getdown = $(obj).parent().parent().next();
 	if(getdown.get(0) != undefined){
	 	var onthis_sort = onthis.find("#sort").val();
	 	var getdown_sort = getdown.find("#sort").val();
	 	//排序号重新赋值
	 	onthis.find("#sort").val(getdown_sort);
	 	getdown.find("#sort").val(onthis_sort);
 	}
 	$(getdown).after(onthis);
}
//修改采购数量
function updateNum(obj, value){
	//验证输入是否为正整数
	var ff = /^\d+$/;
	var val = $(obj).val();
	if(!ff.test(val) && val != ""){
		$(obj).val(value);
	}
	if($(obj).val()==""){
		$(obj).val(value);
	}
}
//显示提示alert
function showJBoxMess(mess, type){
	top.$.jBox.tip.mess=1;
	top.$.jBox.tip(mess,type,{persistent:true,opacity:0});
	if($("#messageBox")){
		$("#messageBox").show();
	}
}
//商品列表上移
function arrowUpTable(obj)
{
 	var onthis = $(obj).parent().parent().parent().parent();
 	var getup = $(obj).parent().parent().parent().parent().prev();
 	if(getup.get(0) != undefined){
	 	var onthis_sort = onthis.find("#sort").val();
	 	var getup_sort = getup.find("#sort").val();
	 	//排序号重新赋值
	 	onthis.find("#sort").val(getup_sort);
	 	getup.find("#sort").val(onthis_sort);
 	}
 	$(getup).before(onthis);
}
//商品列表下移
function arrowDownTable(obj)
{
 	var onthis = $(obj).parent().parent().parent().parent();
 	var getdown = $(obj).parent().parent().parent().parent().next();
 	if(getdown.get(0) != undefined){
	 	var onthis_sort = onthis.find("#sort").val();
	 	var getdown_sort = getdown.find("#sort").val();
	 	//排序号重新赋值
	 	onthis.find("#sort").val(getdown_sort);
	 	getdown.find("#sort").val(onthis_sort);
 	}
 	$(getdown).after(onthis);
}
//加法函数，用来得到精确的加法结果
function accAdd(arg1, arg2) {
    var r1, r2, m, c;
    try {
        r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
        r1 = 0;
    }
    try {
        r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
        r2 = 0;
    }
    c = Math.abs(r1 - r2);
    m = Math.pow(10, Math.max(r1, r2));
    if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", "")) * cm;
        } else {
            arg1 = Number(arg1.toString().replace(".", "")) * cm;
            arg2 = Number(arg2.toString().replace(".", ""));
        }
    } else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
    }
    return (arg1 + arg2) / m;
}
//减法函数，用来得到精确的减法结果
function accSub(arg1, arg2) {
 	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length;
	}catch (e) {
		r1 = 0;
	}
	try {
    	r2 = arg2.toString().split(".")[1].length;
  	}catch (e) {
  		r2 = 0;
	}
	m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
	n = (r1 >= r2) ? r1 : r2;
	return ((arg1 * m - arg2 * m) / m).toFixed(n);
}
//乘法函数，用来得到精确的乘法结果
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try {
        m += s1.split(".")[1].length;
    }
    catch (e) {
    }
    try {
        m += s2.split(".")[1].length;
    }
    catch (e) {
    }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}
//除法函数  
function accDiv(arg1, arg2) {  
    var t1 = 0, t2 = 0, r1, r2;  
    if(arg2==0){
    	return "∞";
    }
    try {  
        t1 = arg1.toString().split(".")[1].length;  
    }  
    catch (e) {  
    }  
    try {  
        t2 = arg2.toString().split(".")[1].length;  
    }  
    catch (e) {  
    }  
    with (Math) {  
        r1 = Number(arg1.toString().replace(".", ""));  
        r2 = Number(arg2.toString().replace(".", ""));  
        return ((r1 / r2) * pow(10, t2 - t1)).toFixed(2);  
    }  
}   